package com.wx.controller.api;

import com.wx.common.WrapMapper;
import com.wx.common.Wrapper;
import com.wx.entity.SysHospital;
import com.wx.holder.WxUserHolder;
import com.wx.service.SysHospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Title:      ApiHospitalController. </p>
 * <p>Description 医院管理 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         <a href="yangwensheng@100doc.com.cn"/>杨文生</a>
 * @since      2020/9/15 18:09
 */
@RestController
@RequestMapping(value = "/api/hospital", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "医院管理(API)", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ApiHospitalController {

    @Resource
    private SysHospitalService sysHospitalService;

    @Resource
    private WxUserHolder wxUserHolder;


    @PostMapping(value = "/list")
    @ApiOperation(httpMethod = "POST", value = "下拉列表查询医院信息")
    public Wrapper<List<SysHospital>> list() {
        List<SysHospital> sysHospitals = sysHospitalService.listHospital();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysHospitals);
    }

    @PostMapping(value = "/listByProvicneCode")
    @ApiOperation(httpMethod = "POST", value = "下拉列表根据省市编码查询医院信息")
    public Wrapper<List<SysHospital>> listByProvinceCode(@RequestBody SysHospital sysHospital) {
        List<SysHospital> sysHospitals = sysHospitalService.listByProvinceCode(sysHospital);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysHospitals);
    }


    @PostMapping("/listHospitalByNurseId")
    @ApiOperation(httpMethod = "POST", value = "下拉选择查询医院列表(只查询当前护士的)")
    public Wrapper<List<SysHospital>> listHospitalByNurseId() {
        WxOAuth2UserInfo userInfo = wxUserHolder.getUserInfo();
        List<SysHospital> list = sysHospitalService.listHospitalByNurseId(userInfo.getOpenid());
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, list);
    }

}
